<?php
    header('Content-type:text/json');
    require "../connection.php";
    $goods_id = $_POST['goods_id'];
    $user_id = $_POST['user_id'];
    $create_time = date("Y-m-d H:i:s",time());
    //先判断用户之前有没有把同一个商品加入到购物车,并且之前是否把购物信息删除过
    $res = $conn->doSql("select * from cart where user_id='$user_id' and goods_id='$goods_id' and status=1");
    if($res){
        $num = $res[0]['goods_num']+1;
        $result = $conn->doSql("update cart set goods_num='$num',update_time='$create_time' where user_id='$user_id' and goods_id='$goods_id'");
     }else{
          $sql = "insert into cart(user_id,goods_id,create_time,update_time) values('$user_id','$goods_id','$create_time','$create_time')";
          $result = $conn->doSql($sql);
     }
    echo json_encode($result);
?>